Skip to content

feat: saga machine example#3

Merged
sam-goodwin merged 3 commits intomainfrom
cdk_pattern-saga
Aug 2, 2022
Merged

feat: saga machine example#3
sam-goodwin merged 3 commits intomainfrom
cdk_pattern-saga

Conversation

@thantos
Copy link
Copy Markdown
Contributor

@thantos thantos commented Jul 25, 2022

Depends on sam-goodwin/functionless#361 (API Gateway Template Formatting)

Based on: https://github.com/cdk-patterns/serverless/tree/main/the-saga-stepfunction

  1. Book a hotel
  2. Book a flight
  3. Pay
  4. Confirm flight
  5. Confirm hotel

If any steps fail, undo any already executed actions.

ex:

If the payment fails, revert the flight booking and the hotel booking.

Two Constructs;

  1. Saga - 1:1 with the source stack. 1 step function and 8 lambda functions for each step.
  2. Optimized Saga - 1 step function, 1 lambda function for creating ID hashes.

@thantos
Copy link
Copy Markdown
Contributor Author

thantos commented Jul 25, 2022

Random Metrics:

  1. Original Code - 9 files (8 lambda, 1 step function construct) - 650 lines of code
  2. Saga in Functionless - 1 file (construct - 8 lambdas 1 step function) - ~450 lines of code - 6.5 seconds cold start, 2.5 seconds after cold start runtime avg
  3. Optimized Saga in Functionless - 1 file (construct - 1 lambda 1 step function) - ~200 lines of code - 2.5 second runtime avg

Copy link
Copy Markdown
Contributor

@sam-goodwin sam-goodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful

@@ -0,0 +1 @@
# replace this No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the content in the original pattern. Should we have the same?

@sam-goodwin
Copy link
Copy Markdown
Contributor

These seem hard to read, do we know the source of these inefficiencies? Both in terms of naming and excessive states?

image
image
image

Equivalent when hand-written without Functionless
image

@sam-goodwin sam-goodwin merged commit e99aaae into main Aug 2, 2022
@sam-goodwin sam-goodwin deleted the cdk_pattern-saga branch August 2, 2022 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants